set RECV_LISTEN(NICK) m_nick

proc m_nick {chid raw parent me} {
	global CHANS_$chid
	global UHOSTS
	global mes
	
	regexp {:([^!]+)!([^@]+)@([^ ]+) NICK :(.+)} $raw -> nick user host newnick
	set chans [$parent tabs]
	foreach chan $chans {
		set userlist [$chan.users get 0 end]
		set idx 0
		foreach user $userlist {
			set n_user [string map {
				"~" ""
				"&" ""
				"@" ""
				"!" ""
				"+" ""
				"%" ""
			} $user]
			if { "$nick" == "$n_user" } {
				output $chan "*** $nick [tr {is known as}] $newnick\n" darkgreen
				
				set prefix ""
				set color black
				if [regexp {(.).+} $user -> firstchar] {
					switch -- $firstchar {
						"~" { set prefix "~"; set color grey39; }
						"@" { set prefix "@"; set color red; }
						"&" { set prefix "&"; set color darkgreen; }
						"%" { set prefix "%"; set color purple; }
						"+" { set prefix "+"; set color blue; }
					}
				}
				
				$chan.users delete $idx
				$chan.users insert $idx "$prefix$newnick"
				$chan.users itemconfigure $idx -foreground $color
			}
			incr idx
		}
	}
	
	if { $nick == $me } {
		set mes($chid) $newnick
	}

	set UHOSTS($nick) "$user@$host"
}
